"""Definition of the ordergoods content type
"""

from zope.interface import implements

from Products.Archetypes import atapi
from Products.ATContentTypes.content import base
from Products.ATContentTypes.content import schemata

# -*- Message Factory Imported Here -*-
from my315ok.grouporder import grouporderMessageFactory as _

from my315ok.grouporder.interfaces import Iordergoods
from my315ok.grouporder.config import PROJECTNAME

ordergoodsSchema = schemata.ATContentTypeSchema.copy() + atapi.Schema((

    # -*- Your Archetypes field definitions here ... -*-

    atapi.IntegerField(
        'currentmembers',
        storage=atapi.AnnotationStorage(),
        widget=atapi.IntegerWidget(
            label=_(u"current members number"),
            description=_(u"Field description"),
        ),
        validators=('isInt'),
    ),


    atapi.DateTimeField(
        'reachedmintime',
        storage=atapi.AnnotationStorage(),
        widget=atapi.CalendarWidget(
            label=_(u"reached minimum members number time"),
            description=_(u"Field description"),
        ),
        validators=('isValidDate'),
    ),


    atapi.DateTimeField(
        'endedtime',
        storage=atapi.AnnotationStorage(),
        widget=atapi.CalendarWidget(
            label=_(u"ended time"),
            description=_(u"Field description"),
        ),
#        required=True,
        validators=('isValidDate'),
    ),


    atapi.DateTimeField(
        'startedtime',
        storage=atapi.AnnotationStorage(),
        widget=atapi.CalendarWidget(
            label=_(u"started time"),
            description=_(u"Field description"),
        ),
        validators=('isValidDate'),
    ),


    atapi.IntegerField(
        'minnums',
        storage=atapi.AnnotationStorage(),
        widget=atapi.IntegerWidget(
            label=_(u"minimum members number"),
            description=_(u"minimum members number for grouporder"),
        ),
#        required=True,
        default=_(u"10"),
        validators=('isInt'),
    ),


    atapi.TextField(
        'tips',
        storage=atapi.AnnotationStorage(),
        widget=atapi.TextAreaWidget(
            label=_(u"tips"),
            description=_(u"Field description"),
        ),
    ),


    atapi.TextField(
        'features',
        storage=atapi.AnnotationStorage(),
        widget=atapi.TextAreaWidget(
            label=_(u"features for goods"),
            description=_(u"Field description"),
        ),
    ),


    atapi.FixedPointField(
        'price',
        storage=atapi.AnnotationStorage(),
        widget=atapi.DecimalWidget(
            label=_(u"price"),
            description=_(u"Field description"),
        ),
#        required=True,
        validators=('isDecimal'),
    ),


    atapi.FixedPointField(
        'discount',
        storage=atapi.AnnotationStorage(),
        widget=atapi.DecimalWidget(
            label=_(u"discount"),
            description=_(u"Field description"),
        ),
#        required=True,
        validators=('isDecimal'),
    ),


    atapi.FixedPointField(
        'originalprice',
        storage=atapi.AnnotationStorage(),
        widget=atapi.DecimalWidget(
            label=_(u"original price"),
            description=_(u"Field description"),
        ),
        validators=('isDecimal'),
    ),


    atapi.ImageField(
        'photo',
        storage=atapi.AnnotationStorage(),
        widget=atapi.ImageWidget(
            label=_(u"big photo"),
            description=_(u"Field description"),
        ),
#        required=True,
        validators=('isNonEmptyFile'),
    ),


    atapi.TextField(
        'text',
        storage=atapi.AnnotationStorage(),
        widget=atapi.RichWidget(
            label=_(u"more details"),
            description=_(u"Field description"),
        ),
#        required=True,
    ),


))

# Set storage on fields copied from ATContentTypeSchema, making sure
# they work well with the python bridge properties.

ordergoodsSchema['title'].storage = atapi.AnnotationStorage()
ordergoodsSchema['description'].storage = atapi.AnnotationStorage()

schemata.finalizeATCTSchema(ordergoodsSchema, moveDiscussion=False)


class ordergoods(base.ATCTContent):
    """a goods content type for group order"""
    implements(Iordergoods)

    meta_type = "ordergoods"
    schema = ordergoodsSchema
    _at_rename_after_creation = True

    title = atapi.ATFieldProperty('title')
    description = atapi.ATFieldProperty('description')

    # -*- Your ATSchema to Python Property Bridges Here ... -*-
    currentmembers = atapi.ATFieldProperty('currentmembers')

    reachedmintime = atapi.ATFieldProperty('reachedmintime')

    endedtime = atapi.ATFieldProperty('endedtime')

    startedtime = atapi.ATFieldProperty('startedtime')

    minnums = atapi.ATFieldProperty('minnums')

    tips = atapi.ATFieldProperty('tips')

    features = atapi.ATFieldProperty('features')

    price = atapi.ATFieldProperty('price')

    discount = atapi.ATFieldProperty('discount')

    originalprice = atapi.ATFieldProperty('originalprice')

    photo = atapi.ATFieldProperty('photo')

    text = atapi.ATFieldProperty('text')


atapi.registerType(ordergoods, PROJECTNAME)
